#ifndef __ENV_H__
#define __ENV_H__

#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <bitset>

#include <cstdlib>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <dirent.h>
#include <execinfo.h>
#include <regex.h>

#include <arpa/inet.h>
#include <mysql/mysql.h>
#include <netinet/in.h>
#include <sys/ipc.h>
#include <sys/mman.h>
#include <sys/msg.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <boost/tuple/tuple.hpp>
#include <boost/any.hpp>


#define MAX_SIZE 65536
#define HALF_SIZE 32768

#define MODULE_WMAIN 0
#define MODULE_WMYSQL 1
#define MODULE_WSOCKET 2
#define MODULE_WPHP 3
#define MODULE_WSIMULATOR 4

using namespace std;

namespace WServer {
namespace GData {
struct ModuleData {
	std::string modulename;
	int msgid;
	ModuleData(std::string mname, int mid) {
		modulename = mname;
		msgid = mid;
	}
};

//env
extern std::vector<ModuleData> modulelist;
extern int logMaxRows;

//common
extern int moduleindex;
extern int msghandlethreadcount;
extern int memorycount;
extern int servermsglength;
extern int wmainindex, wmysqlindex, wsocketindex, wphpindex, wsimulatorindex;
extern int wmainmsgindex, wmysqlmsgindex, wsocketmsgindex, wphpmsgindex, wsimulatormsgindex;
extern int outputfile, outputconsole;

//wmain
extern int maxconn;
extern int maxobject;
extern int msgextthreadcount;

//wmysql
extern std::string dbhost;
extern std::string dbusername;
extern std::string dbpassword;
extern std::string dbname;
extern int handlemysqlcount;
extern int mysqlconnectioncount;
extern int mysqlquerylog;
extern int mysqlsaveplayerdata;

//wsocket
extern int serverport;
extern int socketslog, socketrlog;
extern int socketsendcount, socketrecvcount;

extern int fsmem;

struct wserSocketData {
	int status;
	int hclient;
	in_addr ip;
	int port;
	int objectid;
	int main_tid;
	int socket_tid;
	int mysql_tid;
};
//when a connction arrived, one element will push_back in this vector.
extern struct wserSocketData* clientlist;
}

namespace Env {
void wserInit(int mindex);
void wserUninit();
void initSocketData(int index);
}

}

extern int __rwsize;
extern char* __rwstring;

#endif //__ENV_H__
